package com.ck.core.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * form表单验证工具类
 *
 * @author linqiang
 * @version v1.0
 * @date 2018-12-03 16:14
 */
public class FormUtils {

    public static final String MOBILE_REGEX = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";

    public static final String P_W_D_REGEX = "^[\\w\\d]{6,20}$";
    /** 手机号码长度*/
    public static final int MOBILE_PHONE_NUMBER_LENGTH = 11;

    /**
     * 是否正确手机号
     *
     * @param phone 待验证的手机号
     * @return 是返回true
     */
    public static boolean isMobilePhone(String phone) {
        if (phone.length() != MOBILE_PHONE_NUMBER_LENGTH) {
            return false;
        } else {
            Pattern p = Pattern.compile(MOBILE_REGEX);
            Matcher m = p.matcher(phone);
            return m.matches();
        }
    }

    /**
     * 是否正确密码
     *
     * @param pwd 待验证的手机号
     * @return 是返回true
     */
    public static boolean isPwd(String pwd) {
        Pattern p = Pattern.compile(P_W_D_REGEX);
        Matcher m = p.matcher(pwd);
        return m.matches();
    }
}
